﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace BtoBSWT315.User
{
    public partial class WebSiteCompany2 : System.Web.UI.Page
    {
        public string CID, qymc;
        private void Page_Load(object sender, System.EventArgs e)
        {
            if (Session["user"] == null)
            {
                Response.Redirect("../Default.aspx");
            }
            if (!IsPostBack)
            {
                try
                {
                    // 在此处放置用户代码以初始化页面
                    string user = Session["user"].ToString();

                    Admin.Admin_ClassDb classdb = new Admin.Admin_ClassDb();

                    //定义所需Sql语句
                    string sql = "select id,qymc from qyml where [user]='" + user + "' ";
                    DataTable dataTable = null;

                    dataTable = classdb.GetTables(sql);
                    if (dataTable != null && dataTable.Rows.Count > 0)
                    {
                        foreach (DataRow row in dataTable.Rows)
                        {
                            CID = row["ID"].ToString();
                            qymc = row["qymc"].ToString();
                        }

                        HyperLink1.Text = "http://www.swc315.com/Company";
                        HyperLink1.Text += "/Default.aspx?ID=" + CID;

                        HyperLink1.NavigateUrl = "http://www.swc315.com/Company";
                        HyperLink1.NavigateUrl += "/Default.aspx?ID=" + CID;

                        TextBox1.Text = "<a href=";
                        TextBox1.Text += "http://www.swc315.com/Company";
                        TextBox1.Text += "/Default.aspx?ID=" + CID;
                        TextBox1.Text += " target=_blank>";
                        TextBox1.Text += qymc;
                        TextBox1.Text += "</a>";

                        HyperLink2.NavigateUrl = "http://www.swc315.com/Company";
                        HyperLink2.NavigateUrl += "/Default.aspx?ID=" + CID;

                    }

                    //定义所需SQL
                    string sql1 = "update qyml set url='" + HyperLink1.Text + "' where ID=" + CID;

                    //引入数据库操作类
                    //Admin.Admin_ClassDb classdb = new Admin.Admin_ClassDb();
                    classdb.GetNonResult(sql1);
                }
                catch
                {
                    throw new Exception("数据库操作失败!");
                }
            }
        }

        #region Web 窗体设计器生成的代码
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
            //
            InitializeComponent();
            base.OnInit(e);
        }

        /// <summary>
        /// 设计器支持所需的方法 - 不要使用代码编辑器修改
        /// 此方法的内容。
        /// </summary>
        private void InitializeComponent()
        {
            this.Load += new System.EventHandler(this.Page_Load);

        }
        #endregion
    }
}